import plugin from '../../lib/plugins/plugin.js'
import {
    segment
}
    from 'oicq'
import fetch from "node-fetch";

let url = ""

export class englishZcx1013 extends plugin {
    constructor() {
        super({
            /** 功能名称 */
            name: '贝壳英语每日一句',
            /** 功能描述 */
            dsc: '',
            event: 'message',
            priority: 1145,
            rule: [
                {
                    reg: '^#英语句子.*$',
                    fnc: 'english'
                }
            ]

        })
    }

    async english(e) {
        if (e.isGroup) {
            let img = []
            url = `https://apiv3.shanbay.com/weapps/dailyquote/quote/`;

            let response = ""; //调用接口获取数据
            let res = ""; //结果json字符串转对象
            let tempLast = [];
            try {
                response = await fetch(url);
                res = await response.json();
                img[0] = res.poster_img_urls[0];
            } catch {
                return
            }
            tempLast = img[0].split(",");
            if (res == "") {
                e.reply('接口调用失败')
            }
            //发送消息
            await e.reply(segment.image(tempLast[0]))
        }
    }

}